
export const ApiPackageMixins = {
	computed: {},
	data() {
		return {
			
		}
	},
	created() {
		
	},
	methods: {
		//网页推送消息解析
		webMessageHandle (msgData) {
			let msgType = msgData.type;
			switch(msgType){
				case 'showMsg':
					this.appShowToast(msgData.data);
				break;
				case 'hideMsg':
					this.appHideToast(msgData.data);
				break;
				//设置粘贴板
				case 'setClipboard':
					this.setClipboard(msgData.data)
				break;
				//获取粘贴板的数据
				case 'getClipboard':
					this.getClipboardData(msgData.data)
				break;
				//扫码
				case 'scanCode':
					this.scanCode(msgData.data)
				break;
				//隐藏软键盘
				case 'hideKeyboard':
					this.hideKeyboard()
				break;
				//返回一些设备信息
				case 'getSystemInfo':
					this.sendMessage(msgData.data.busName,{state:'success',res:JSON.stringify(this.sysInfo)});
				break;
				default:
					console.log('未知消息类型')
				break;
			}
		},
		//消息提示
		appShowToast(data){
			uni.showToast({
			  title: data.title || '提示', // 提示的内容
			  icon: data.icon || 'success', // 图标类型：'success' 或 'loading' 或 'none'
			  duration: data.duration || 1000 ,// 显示时长，毫秒
			  mask: data.mask || false
			});
		},
		//隐藏提示
		appHideToast(data){
			uni.hideToast();
		},
		//设置粘贴板
		setClipboard(data){
			const self = this;
			let _data = {
				data: data.data,
				showToast: data.showToast,
				success: function(){
					self.sendMessage(data.busName,{state:'success'})
				},
				fail: function(res){
					self.sendMessage(data.busName,{state:'fail',res})
				}
			};
			uni.setClipboardData(_data);
		},
		//获取粘贴板数据
		//h5访问是无法正常获取粘贴板中的数据，dcloud回答是需要访问链接为https才能使用
		getClipboardData(data){
			const self = this;
			let _data = {
				success: function(res){
					self.sendMessage(data.busName,{state:'success',res:res});
				},
				fail: function(res){
					self.sendMessage(data.busName,{state:'fail',res:res});
				}
			};
			uni.getClipboardData(_data);
		},
		//扫码 吊起移动端原始的扫码页面
		scanCode(data){
			const self = this;
			uni.scanCode({
				success: function (res) { 
					self.sendMessage(data.busName,{state:'success',res:res});
				},
				fail:function(res) {
					self.sendMessage(data.busName,{state:'fail',res:res});
				}
			});
		},
		//隐藏软键盘
		hideKeyboard(){
			setTimeout(()=>{
				uni.hideKeyboard()
			},100)
		}
		
	}
}